<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <h1 @click="message='hello 前端开发'">{{message}}</h1>
    <h1 @click="changePerson">{{person}}</h1>
  </div>
  <script src="../../javascript//vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#app",
      data() {
        return {
          message: "Hello Vue",
          person: {
            name: "陶品奇",
            age: 22,
          }
        }
      },
     methods:{
      /*
      vue2的响应式是通过Object.defineProperty()实现的，当一个vue实例被创建时
      vue会遍历data对象中的所有属性，并且使用Object.defineProperty()方法将所有属性转换为get以及set，这样当data对象的属性被修改时，vue会自动进行视图的更新
      vm.$set( target, propertyName/index, value )
        - **参数**：
          - `{Object | Array} target`
          - `{string | number} propertyName/index`
          - `{any} value`
        - **返回值**：设置的值

      vm.$delete( target, propertyName/index )
        - **参数**：
          - `{Object | Array} target`
          - `{string | number} propertyName/index`
*/
      changePerson() {
        //delete this.person.age 视图不更新
        this.$delete(this.person,"name")
        this.$set(this.person,"age")
      }
     }
    })
  </script>
</body>

</html>